package com.enba.mallapi.module.auth.controller.req;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotBlank;
import lombok.Data;

@Data
@ApiModel(value = "登陆请求参数")
public class LoginReq {

  @NotBlank(message = "用户名不能为空")
  @ApiModelProperty(value = "用户名", required = true)
  private String username;

  @NotBlank(message = "密码不能为空")
  @ApiModelProperty(value = "密码", required = true)
  private String password;

  @ApiModelProperty(value = "验证码键", required = true)
  @NotBlank(message = "验证码不能为空")
  private String captchaKey;

  @ApiModelProperty(value = "验证码值", required = true)
  @NotBlank(message = "验证码不能为空")
  private String captchaValue;

  /** 入参校验 */
  public void check() {
    if (username == null || username.length() < 4 || username.length() > 20) {
      throw new IllegalArgumentException("用户名长度为4-20位");
    }
    if (password == null || password.length() < 6 || password.length() > 20) {
      throw new IllegalArgumentException("密码长度为6-20位");
    }

    if (captchaValue == null || captchaValue.length() != 4) {
      throw new IllegalArgumentException("验证码值长度为4位");
    }
  }
}
